<template>
  <div class="page">
    <div class="bg">
      <div class="left">
        <div class="logo-title-box">
          <div class="logo-title">
            <!-- <div class="logo">
              <img :src="logoUrl" alt="" />
            </div>
            <div class="title">精卫安</div> -->
          </div>
        </div>
        <div class="login-bg-box">
          <div class="login-bg">
            <img :src="loginUrl" alt="" />
          </div>
        </div>
        <div class="space"></div>
      </div>
      <div class="right" v-show="isLogin">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="账号登录" name="first">
            <div class="form-box">
              <el-form :model="loginForm" :rules="rules" ref="refLoginForm">
                <el-form-item
                  prop="username"
                  style="margin-top: 26px"
                  class="inputDeep"
                >
                  <el-input
                    clearable
                    placeholder="请输入用户名/手机号"
                    maxlength="20"
                    class="inputDeep"
                    @blur="usernameBlur"
                    v-model.trim="loginForm.username"
                  >
                    <i
                      slot="prefix"
                      class="iconfont jurassic_user img-style"
                    ></i>
                  </el-input>
                </el-form-item>
                <el-form-item prop="password" class="inputDeep">
                  <el-input
                    :type="flag ? 'text' : 'password'"
                    clearable
                    placeholder="请输入登录密码"
                    maxlength="16"
                    @blur="pwdBlur"
                    v-model.trim="loginForm.password"
                  >
                    <i slot="prefix" class="iconfont mima img-style"></i>
                    <i
                      slot="suffix"
                      :class="[
                        'iconfont',
                        flag ? 'zhengyan' : 'biyanjing',
                        'img-style',
                      ]"
                      style="cursor: pointer"
                      @click="pwsShow"
                    ></i>
                  </el-input>
                </el-form-item>
                <el-form-item prop="code" class="inputDeep">
                  <div class="verification-code-box">
                    <!--@keyup.enter.native="submitForm" -->
                    <el-input
                      clearable
                      v-model.trim="loginForm.code"
                      placeholder="请输入验证码"
                      oninput="value=value.replace(/^ +| +$/g,'')"
                      maxlength="4"
                      class="verification-input"
                      @blur="codeBlur"
                    >
                      <i
                        slot="prefix"
                        class="iconfont yanzhengma img-style"
                      ></i>
                    </el-input>
                    <div
                      @click="reqVerification"
                      v-loading="imageCodeSrc ? false : true"
                    >
                      <img class="img" :src="imageCodeSrc" />
                    </div>
                  </div>
                </el-form-item>
                <!-- <el-form-item class="inputDeep">
                  <div style="height: 50px; border: 1px solid #ccc">
                    滑动验证
                  </div>
                </el-form-item> -->
              </el-form>

              <div class="agreement_box">
                <el-checkbox v-model="checked">我已阅读并同意</el-checkbox>

                <a href="/serviceTerms" target="_blank">《服务条款》</a>
                <a href="/privacy" target="_blank">《隐私政策》</a>
              </div>

              <!-- <div class="agreement_box">
                <a href="/loginProtocol" target="_blank">《第三方账号创建登录协议》</a>
              </div> -->

              <div class="login-button">
                <el-button
                  type="primary"
                  :loading="loading"
                  @click="submitForm"
                  @keyup.enter="keyDown(e)"
                >
                  {{ loading ? "正在登录..." : "登 录" }}
                </el-button>
              </div>

              <div class="footer_btns">
                <div class="remember_pw">
                  <!-- <el-switch :width="40" active-text="记住密码" v-model="isRemember" active-color="#7978fa"
                    inactive-color="#5a5a80">
                  </el-switch> -->
                </div>
                <span class="forgot_link" @click="goForgetPwd">忘记密码?</span>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane label="短信登录" name="second">
            <div class="form-box">
              <el-form :model="noteForm" :rules="noterules" ref="refLoginForm1">
                <el-form-item
                  prop="mobile"
                  style="margin-top: 26px"
                  class="inputDeep"
                >
                  <el-input
                    clearable
                    placeholder="请输入手机号"
                    maxlength="11"
                    v-model.trim="noteForm.mobile"
                  >
                    <i slot="prefix" class="iconfont shoujihao1 img-style"></i>
                  </el-input>
                </el-form-item>
                <el-form-item prop="code" class="inputDeep">
                  <div style="position: relative">
                    <el-input
                      placeholder="请输入短信验证码"
                      maxlength="6"
                      v-model.trim="noteForm.code"
                    >
                      <i
                        slot="prefix"
                        class="iconfont yanzhengma img-style"
                      ></i>
                    </el-input>
                    <div @click="smsCodeClick2" class="code">
                      <span v-show="showCountDown2">获取验证码</span>
                      <span v-show="!showCountDown2"
                        >{{ countDown2 }}秒重新获取</span
                      >
                    </div>
                  </div>
                </el-form-item>
              </el-form>

              <div class="agreement_box">
                <el-checkbox v-model="checked">我已阅读并同意</el-checkbox>

                <a href="/serviceTerms" target="_blank">《服务条款》</a>
                <a href="/privacy" target="_blank">《隐私政策》</a>
              </div>

              <!-- <div class="agreement_box">
                <a href="/loginProtocol" target="_blank">《第三方账号创建登录协议》</a>
              </div> -->

              <div class="login-button">
                <el-button
                  type="primary"
                  :loading="loading"
                  @click="submitForm"
                  @keyup.enter="keyDown(e)"
                >
                  {{ loading ? "正在登录..." : "登 录" }}
                </el-button>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>
        <!-- <div id="weixin"></div>

        <div class="login_type">
          <i class="iconfont weixin-copy iconStyle" @click="wxlogin"></i>
          <span>微信快捷登录</span>
        </div> -->
        <div
          style="
            position: absolute;
            bottom: 0;
            text-align: center;
            width: 80%;
            margin-bottom: 5px;
            color: #909399;
            font-size: 14px;
          "
        >
          v 1.4.0
          <span v-if="$store.state.config.environment == 'development'"
            >开发版</span
          >
          <span v-else-if="$store.state.config.environment == 'test'"
            >测试版</span
          >
          <span v-else></span>
        </div>
      </div>
      <div class="right" v-show="!isLogin">
        <div
          style="
            color: #7978fa;
            font-size: 18px;
            font-weight: 600;
            text-align: center;
            margin-bottom: 40px;
          "
        >
          找回密码
        </div>
        <div class="form-box">
          <el-form :model="findForm" :rules="findRules" ref="refFindForm">
            <el-form-item prop="mobile">
              <el-input
                clearable
                placeholder="请输入手机号"
                oninput="value=value.replace(/[^\d]/g,'')"
                @blur="findForm.mobile = $event.target.value"
                v-model="findForm.mobile"
                maxlength="11"
              >
                <i slot="prefix" class="iconfont shoujihao1 img-style"></i>
              </el-input>
            </el-form-item>

            <el-form-item prop="smsCode">
              <div style="position: relative">
                <el-input
                  placeholder="请输入短信验证码"
                  maxlength="6"
                  v-model.trim="findForm.smsCode"
                  class="verification-input"
                >
                  <i slot="prefix" class="iconfont duanxin img-style"></i>
                </el-input>
                <div @click="smsCodeClick" class="code">
                  <span v-show="showCountDown">获取验证码</span>
                  <span v-show="!showCountDown">{{ countDown }}秒重新获取</span>
                </div>
              </div>
            </el-form-item>
            <el-form-item prop="passWord">
              <el-input
                clearable
                placeholder="请设置6-16位登录密码"
                v-model="findForm.passWord"
                readOnly
                @focus="onFocus"
                @blur="onBlur"
                @input.native="onInput($event, findForm.passWord)"
                @mousedown.native="onMousedown"
                :type="flag2 ? 'text' : 'password'"
              >
                <i slot="prefix" class="iconfont mima img-style"></i>
                <i
                  slot="suffix"
                  :class="[
                    'iconfont',
                    flag2 ? 'zhengyan' : 'biyanjing',
                    'img-style',
                  ]"
                  style="cursor: pointer"
                  @click="pwsShow2"
                ></i>
              </el-input>
            </el-form-item>
            <el-form-item prop="verifyPassWord">
              <el-input
                clearable
                placeholder="请再次输入新的登录密码"
                v-model="findForm.verifyPassWord"
                readOnly
                @focus="onFocus"
                @blur="onBlur"
                @input.native="onInput($event, findForm.verifyPassWord)"
                @mousedown.native="onMousedown"
                :type="flag3 ? 'text' : 'password'"
              >
                <i slot="prefix" class="iconfont mima img-style"></i>
                <i
                  slot="suffix"
                  :class="[
                    'iconfont',
                    flag3 ? 'zhengyan' : 'biyanjing',
                    'img-style',
                  ]"
                  style="cursor: pointer"
                  @click="pwsShow3"
                ></i>
              </el-input>
            </el-form-item>

            <el-form-item class="login-button">
              <el-button type="theme" @click="submitFindPwd">确 定</el-button>
            </el-form-item>
            <div style="text-align: center">
              <span class="forgot_link2" @click="backLogin"
                >已有账号？立即登录</span
              >
            </div>
          </el-form>
        </div>
      </div>
    </div>
    <div class="triangle"></div>
    <organization ref="reforganization"></organization>
  </div>
</template>

<script>
import {
  forgetPassword,
  reqImageCode,
  getSmsCode,
  reqHasSmsCode,
  reqSmsLogin,
  reqOrgList,
  reqAgencyList,
} from "@/api/api.js";
import { initDynamicRoutes } from "@router"; //动态路由
import { mapMutations, mapState } from "vuex";
import asc from "@utils/asc.js";
import PreBrowserDefaultPassPop from "@utils/mixin/PreBrowserDefaultPassPop";
import {
  validateUsernameAndMobile,
  validMobile,
  validateCode,
  validatePass,
} from "@/utils/validate";
import "@/utils/wxLogin"; // 微信官网扫码js
import organization from "./components/organization";

export default {
  name: "login",
  components: {
    organization,
  },
  mixins: [PreBrowserDefaultPassPop],
  data() {
    var checkPass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.findForm.passWord) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      v_loading: false,
      checked: false,
      findRules: {
        mobile: [
          {
            required: true,
            message: "请输入手机号",
            trigger: "blur",
          },
          {
            validator: validMobile,
          },
        ],
        passWord: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
          { validator: validatePass },
        ],
        verifyPassWord: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
          { validator: checkPass },
        ],
        smsCode: [
          {
            required: true,
            message: "请输入验证码",
            trigger: "blur",
          },
        ],
      },
      showCountDown: true, //显示倒计时
      countDown: "", //倒计时一分钟
      showCountDown2: true, //显示倒计时
      countDown2: "", //倒计时一分钟
      findForm: {
        mobile: "",
        passWord: "",
        verifyPassWord: "",
        smsCode: "",
      },
      isLogin: true,
      logoUrl: require("@assets/images/logo4.png"),
      loginUrl: require("@assets/images/login_bg.png"),
      flag: false,
      flag2: false,
      flag3: false,
      loginForm: {
        // username: "15526276121",
        // password: "111111",
        username: "",
        password: "",
        code: "",
      },
      noteForm: {
        mobile: "",
        code: "",
      },
      noterules: {
        mobile: [
          {
            required: true,
            message: "请输入手机号",
            trigger: "blur",
          },
          {
            validator: validMobile,
          },
        ],
        code: [
          {
            required: true,
            message: "请输入验证码",
            trigger: "blur",
          },
        ],
      },
      imageCodeSrc: "", //图形验证码地址
      loading: false, //点击登录加载中
      rules: {
        username: [
          {
            required: true,
            message: "请输入用户名/手机号",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
        ],
        code: [
          {
            required: true,
            message: "请输入验证码",
            trigger: "blur",
          },
        ],
      },
      // isRemember: true, //登录状态
      countDown3: 0, //防止图片验证码频繁点击
      activeName: "first",
      uuid: "",
    };
  },
  created() {
    var link = document.querySelector("link[rel*='icon']");
    link.href = "data:;base64,="; //修改浏览器logo
    // this.reqVerification2();
    // this.getRememberPwd();
  },
  computed: {
    ...mapState(["user"]), //系统配置项
  },
  methods: {
    ...mapMutations(["saveUserId"]),
    // 微信快捷登录
    wxlogin() {
      var obj = new WxLogin({
        self_redirect: true, // 这个为true的时候是直接在扫码的区域展现页面，我不需要，所以直接写false
        id: "weixin", // 盒子容器id名称
        appid: "wx32be180d426fd678", // 申请的网站应用appid
        scope: "snsapi_login", // 网页授权，目前网页只有这一种方式，静默授权
        redirect_uri: encodeURIComponent("https://sc.yuanliuiot.com/org/list"), // 扫码成功后 跳转的地址 申请网站应用时填写的回调域名，这里对应即可
        state: Math.random(), // 简单的随机数+Session用来校验
        style: "", // black、white两种可以选择，二维码样式 (默认black)
        href: "", // 自定义样式链接，只能使用https接或者base64编码的地址修改二堆码的样式，要经过base64位转码，地址为(https://the-x,Cn/base64/))
      });
    },
    // 点击获取图形验证码
    async reqVerification2() {
      const res = await reqImageCode();
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      this.$nextTick(() => {
        this.imageCodeSrc = res.data.imageCode;
        this.uuid = res.data.uuid;
      });
    },
    // 点击回到登录
    backLogin() {
      this.isLogin = true;
    },
    // 确定修改密码
    submitFindPwd() {
      this.$refs.refFindForm.validate(async (valid) => {
        if (valid) {
          let res = await forgetPassword({
            mobile: this.findForm.mobile,
            smsCode: this.findForm.smsCode,
            passWord: this.findForm.passWord,
            verifyPassWord: this.findForm.verifyPassWord,
          });
          if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
          this.$modal.notifySuccess("找回密码成功");
          this.findForm = {
            mobile: "",
            passWord: "",
            verifyPassWord: "",
            smsCode: "",
          };
          this.$refs.refFindForm.resetFields();
          this.showCountDown = true;
          this.countDown = "";
          this.backLogin();
        }
      });
    },
    // 点击获取短信验证码
    async smsCodeClick() {
      if (!this.findForm.mobile)
        return this.$modal.notifyWarning("请输入手机号");
      if (this.findForm.mobile.length < 11)
        return this.$modal.notifyWarning("手机号码为11位数字");
      if (!this.showCountDown) return; //60s内只需发一次验证码
      // 验证手机号码是否存在
      let res1 = await reqHasSmsCode({ mobile: this.findForm.mobile });
      if (res1.code !== 20000) return this.$modal.notifyWarning(res.message);
      if (res1.data.count == 0)
        return this.$modal.notifyWarning("手机号码不存在，请输入正确的手机号");
      // 发送验证码
      let res = await getSmsCode({
        mobile: this.findForm.mobile,
      });
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      this.$modal.notifyWarning("请注意查收手机短信验证码");

      this.showCountDown = false;
      this.countDown = 60;
      let intervalId = setInterval(() => {
        if (this.countDown > 0 && this.countDown <= 60) {
          this.countDown--;
        } else {
          this.showCountDown = true;
          clearInterval(intervalId);
          intervalId = null;
        }
      }, 1000);
    },
    // 点击获取短信验证码
    async smsCodeClick2() {
      if (!this.noteForm.mobile)
        return this.$modal.notifyWarning("请输入手机号");
      if (this.noteForm.mobile.length < 11)
        return this.$modal.notifyWarning("手机号码为11位数字");
      if (!this.showCountDown2) return; //60s内只需发一次验证码
      // 验证手机号码是否存在
      let res1 = await reqHasSmsCode({ mobile: this.noteForm.mobile });
      if (res1.code !== 20000) return this.$modal.notifyWarning(res.message);
      if (res1.data.count == 0)
        return this.$modal.notifyWarning("手机号码不存在，请输入正确的手机号");
      // 发送验证码
      let res = await getSmsCode({
        mobile: this.noteForm.mobile,
      });
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      this.$modal.notifyWarning("请注意查收手机短信验证码");

      this.showCountDown2 = false;
      this.countDown2 = 60;
      let intervalId = setInterval(() => {
        if (this.countDown2 > 0 && this.countDown2 <= 60) {
          this.countDown2--;
        } else {
          this.showCountDown2 = true;
          clearInterval(intervalId);
          intervalId = null;
        }
      }, 1000);
    },
    // 记住密码写入表单
    getRememberPwd() {
      let u = JSON.parse(window.localStorage.getItem("u"));
      if (!(u && u.username && u.password)) return;
      this.loginForm.username = u.username;
      this.loginForm.password = u.password;
      // this.isRemember = true;
    },
    handleClick(tab) {
      // console.log(tab.paneName);
      this.activeName = tab.paneName;
    },
    // 密码显影
    pwsShow() {
      this.flag = !this.flag;
    },
    pwsShow2() {
      this.flag2 = !this.flag2;
    },
    pwsShow3() {
      this.flag3 = !this.flag3;
    },
    // 点击获取图形验证码
    async reqVerification() {
      // this.$notify.closeAll();
      if (this.countDown3 != 0)
        return this.$modal.notifyWarning(
          `请${this.countDown3}s后重新获取验证码`
        );

      const res = await reqImageCode();
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      this.$nextTick(() => {
        this.imageCodeSrc = res.data.imageCode;
        this.uuid = res.data.uuid;
      });

      //倒计时
      this.countDown3 = 10;
      let intervalId = setInterval(() => {
        if (this.countDown3 > 0 && this.countDown3 <= 10) {
          this.countDown3--;
        } else {
          clearInterval(intervalId);
          intervalId = null;
        }
      }, 1000);
    },
    // 过期重新获取图形验证码
    async Verification() {
      const res = await reqImageCode();
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      this.$nextTick(() => {
        this.imageCodeSrc = res.data.imageCode;
        this.uuid = res.data.uuid;
      });
    },
    // 手机号/用户名blur
    usernameBlur(e) {
      this.loginForm.username = e.target.value;
    },
    // 密码blur
    pwdBlur(e) {
      this.loginForm.password = e.target.value;
    },
    // 验证码blur
    codeBlur(e) {
      this.loginForm.code = e.target.value;
    },
    // 点击登录
    submitForm() {
      if (this.activeName == "first") {
        // 密码登录
        this.$refs.refLoginForm.validate(async (valid) => {
          if (valid) {
            if (!this.checked)
              return this.$modal.notifyWarning(
                "请阅读并勾选“服务条款与隐私协议”"
              );
            let params = {
              username: this.loginForm.username,
              password: this.loginForm.password,
              code: this.loginForm.code,
            };
            this.loading = true;
            this.$store
              .dispatch("Login", params)
              .then(async (resres) => {
                // 判断是不是超级管理员
                if (resres.role.name == "SUPER_ADMIN") {
                  this.$router.replace({
                    path: "/system/member",
                  });
                  return;
                }
                // 系统运维
                if (resres.role.name == "PLATFORM_ADMIN") {
                  this.$router.replace({
                    path: "/tenant/list",
                  });
                  return;
                }
                // 内部角色
                if (resres.role.name == "INTERIOR") {
                  this.$router.replace({
                    path: "/export/export",
                  });
                  return;
                }
                if (
                  resres.role.name == "TENANT_ADMIN" ||
                  resres.role.name == "ORG_ADMIN" ||
                  resres.role.name == "INSTERALL_USER" ||
                  resres.role.name == "UNIT_ADMIN"
                ) {
                  this.$router.replace({
                    path: "/datav",
                  });
                  return;
                }
                this.$router.replace({
                  path: "/",
                });

                // 登录选择组织机构
                // var res = await reqAgencyList( {
                //   userId: resres.id,
                //   roleName: resres.role.name,
                //   tenantId: resres.tenantId,
                //   agencyName: "",
                // });
                // if (res.code !== 20000)
                //   return this.$modal.notifyWarning(res.message);
                // let { rows } = res.data;
                // if (
                //   (resres.role.name == "ORG_ADMIN" ||
                //     resres.role.name == "INSTERALL_USER") &&
                //   rows.length > 1
                // ) {
                //   this.$refs.reforganization.dialogVisible = true;
                // } else {
                // 判断是不是超级管理员
                // if (resres.role.name == "SUPER_ADMIN") {
                //   this.$router.replace({
                //     path: "/system/member",
                //   });
                //   return;
                // }
                // // 系统运维
                // if (resres.role.name == "PLATFORM_ADMIN") {
                //   this.$router.replace({
                //     path: "/tenant/list",
                //   });
                //   return;
                // }
                // 租户管理员 || 单位管理员
                // if (
                //   resres.role.name == "TENANT_ADMIN" ||
                //   resres.role.name == "ORG_ADMIN" ||
                //   resres.role.name == "INSTERALL_USER"
                // ) {
                //   this.$store.commit("saveOrganizationInfo", {
                //     orgId: rows[0].id,
                //     orgName: rows[0].orgName,
                //   }); //保存信息，使页面刷新信息还存在
                //   this.$router.replace({
                //     path: "/datav",
                //   });
                //   return;
                // }
                // this.$router.replace({
                //   path: "/",
                // });
                // }
                //vuex异步请求
                this.loading = false;
                // if (this.isRemember) {
                //   this.rememberPwd(params);
                // } else {
                //   this.notRememberPwd();
                // }
              })
              .catch(async (err) => {
                if (err.code == 11133) {
                  this.$confirm(
                    "账号未设置登陆密码，请使用短信登录",
                    "温馨提示",
                    {
                      confirmButtonText: "确认",
                      cancelButtonText: "取消",
                      type: "warning",
                    }
                  )
                    .then(() => {
                      this.activeName = "second";
                    })
                    .catch(() => {});
                } else {
                  this.$modal.notifyWarning(err.message);
                }
                this.loading = false;
                this.Verification();
                this.loginForm.code = "";
              });
          } else {
            // this.loginForm.code = "";
          }
        });
        return;
      }
      // 短信登录
      this.$refs.refLoginForm1.validate(async (valid) => {
        if (valid) {
          if (!this.checked)
            return this.$modal.notifyWarning(
              "请阅读并勾选“服务条款与隐私协议”"
            );
          this.loading = true;
          this.$store
            .dispatch("Login", this.noteForm)
            .then(async (resres) => {
              // 判断是不是超级管理员
              if (resres.role.name == "SUPER_ADMIN") {
                this.$router.replace({
                  path: "/system/member",
                });
                return;
              }
              // 系统运维
              if (resres.role.name == "PLATFORM_ADMIN") {
                this.$router.replace({
                  path: "/tenant/list",
                });
                return;
              }
              // 内部角色
              if (resres.role.name == "INTERIOR") {
                this.$router.replace({
                  path: "/export/export",
                });
                return;
              }
              // 租户管理员 || 单位管理员
              if (
                resres.role.name == "TENANT_ADMIN" ||
                resres.role.name == "ORG_ADMIN" ||
                resres.role.name == "INSTERALL_USER" ||
                resres.role.name == "UNIT_ADMIN"
              ) {
                // this.$store.commit("saveOrganizationInfo", {
                //   orgId: rows[0].id,
                //   orgName: rows[0].orgName,
                // }); //保存信息，使页面刷新信息还存在
                this.$router.replace({
                  path: "/datav",
                });
                return;
              }
              this.$router.replace({
                path: "/",
              });

              // 登录选择组织机构
              // var res = await reqAgencyList( {
              //   userId: resres.id,
              //   roleName: resres.role.name,
              //   tenantId: resres.tenantId,
              //   agencyName: "",
              // });
              // if (res.code !== 20000)
              //   return this.$modal.notifyWarning(res.message);
              // let { rows } = res.data;
              // if (
              //   (resres.role.name == "ORG_ADMIN" ||
              //     resres.role.name == "INSTERALL_USER") &&
              //   rows.length > 1
              // ) {
              //   this.$refs.reforganization.dialogVisible = true;
              // } else {

              // }
              //vuex异步请求
              this.loading = false;
              // if (this.isRemember) {
              //   this.rememberPwd(params);
              // } else {
              //   this.notRememberPwd();
              // }
            })
            .catch(async (err) => {
              this.$modal.notifyWarning(err.message);
              this.loading = false;
              this.Verification();
              this.loginForm.code = "";
            });
          // .dispatch("Login", this.noteForm)
          // .then((res) => {
          //   //vuex异步请求
          //   this.loading = false;
          //   if (this.isRemember) {
          //     this.rememberPwd(this.noteForm);
          //   } else {
          //     this.notRememberPwd();
          //   }
          // })
          // .catch((err) => {
          //   this.loading = false;
          //   this.$modal.notifyWarning(err.message);
          //   // this.reqVerification();
          //   this.loginForm.code = "";
          // });
        } else {
          // this.reqVerification();
          // this.loginForm.code = "";
        }
      });
    },
    // 点击回车键登录
    keyDown(e) {
      // 回车则执行登录方法 enter键的ASCII是13
      if (e.keyCode == 13) {
        //|| e.keyCode == 100
        this.submitForm(); // 定义的登录方法
      }
    },
    // 永久存储记住密码
    rememberPwd(data) {
      window.localStorage.setItem(
        "u",
        // asc.encrypt(
        JSON.stringify({
          username: data.username,
          password: data.password,
        })
        // )
      );
    },
    // 不记住密码
    notRememberPwd() {
      window.localStorage.removeItem("u");
    },
    goForgetPwd() {
      // this.$router.push({
      //   path: "/find-password",
      // });
      this.isLogin = false;
    },
  },
  mounted() {
    this.reqVerification2();
    this.getRememberPwd();
    // 绑定监听事件
    window.addEventListener("keydown", this.keyDown);
  },
  destroyed() {
    // 销毁事件
    window.removeEventListener("keydown", this.keyDown, false);
  },
};
</script>

<style lang="less" scoped>
@import url("login.less");
</style>
